#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;

//vector的构造
void test0(){
    int arr[5] = {1,2,3,4,5};
    vector<int> nums;
    vector<long> nums2(10);

    for(auto & ele : nums2){
        cout << ele << " ";
    }
    cout << endl;

    vector<int> nums3(10,20);
    for(auto & ele : nums3){
        cout << ele << " ";
    }
    cout << endl;

    vector<int> nums4{1,2,3,4,5};
    for(auto & ele : nums4){
        cout << ele << " ";
    }
    cout << endl;

    /* auto it = nums4.begin(); */
    vector<int>::iterator it = nums4.begin();
    vector<int>::iterator it2 = nums4.end();
    --it2;
    vector<int> nums5(it,it2);
    for(auto & ele : nums5){
        cout << ele << " ";
    }
    cout << endl;

    vector<int> nums6(arr,arr + 5);
    for(auto & ele : nums6){
        cout << ele << " ";
    }
    cout << endl;
}

//vector的遍历
void test1(){
    vector<int> nums{1,2,3,4,5};
    for(size_t idx = 0; idx < nums.size(); ++idx){
        cout << nums[idx] << " ";
    }
    cout << endl;

    //增强for循环
    for(auto & ele : nums){
        cout << ele << " ";
    }
    cout << endl;

    //迭代器方式遍历
    auto it = nums.begin();
    for(; it != nums.end(); ++it){
        cout << *it << " ";
    }
    cout << endl;
}

//vector的常用操作
void test2(){
    vector<int> number;
    vector<int> nums{1,2,3,4,5};
    cout << number.empty() << endl;
    cout << nums.empty() << endl;

    size_t count = nums.size();
    cout << count << endl;
    cout << nums.capacity() << endl;

    cout << endl;
    nums.push_back(9);
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    nums.pop_back();
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;
    
    nums.shrink_to_fit();
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;
    nums.clear();
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;
}

void test3(){
    vector<int> nums(10);
    cout << nums.size() << endl;
    cout << nums.capacity() << endl;

    //预期vector大概会存放多少个元素
    //可以使用reserve开辟元素的空间，但是不存放元素
    vector<int> nums2;
    nums2.reserve(20);
    cout << nums2.size() << endl;
    cout << nums2.capacity() << endl;
}




int main(void){
    test3();
    return 0;
}
